﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WindowsPhone.Marketplace
{
    /// <summary>
    /// Holds fully parsed Marketplace Data
    /// </summary>
    /// <remarks>
    /// All properties are created with default (empty) objects, i.e. will not be null
    /// </remarks>
    public class MarketplaceData
    {
        public Dictionary<string, MarketplaceLang> Marketplaces { get; set; }

        public Dictionary<string, MarketplaceApp>       Apps       { get; set; }
        public Dictionary<string, MarketplacePublisher> Publishers { get; set; }
        public Dictionary<string, MarketplaceCategory>  Categories { get; set; }

        public Dictionary<string, List<MarketplaceApp>> LicenseRights { get; set; }
        public Dictionary<string, List<MarketplaceApp>> PaymentTypes { get; set; }

        public MarketplaceData()
        {
            Marketplaces = new Dictionary<string, MarketplaceLang>();

            Apps       = new Dictionary<string, MarketplaceApp>();
            Publishers = new Dictionary<string, MarketplacePublisher>();
            Categories = new Dictionary<string, MarketplaceCategory>();

            LicenseRights = new Dictionary<string, List<MarketplaceApp>>();
            PaymentTypes  = new Dictionary<string, List<MarketplaceApp>>();
        }
    }

    public class MarketplaceLang : MarketplaceData
    {
        public string LanguageCode { get; private set; }

        public MarketplaceLang(string langCode)
            : base()
        {
            LanguageCode = langCode;
            Marketplaces = null;
        }
    }

    public class MarketplaceApp
    {
        public string Title { get; set; }
        public string Id { get; set; }
        public DateTime ReleaseDate { get; set; }
        public DateTime Updated { get; set; }
        public string Version { get; set; }
        public string ShortDescription { get; set; }
        public decimal AverageUserRating { get; set; }
        public int UserRatingCount { get; set; }
        public string ImageId { get; set; }

        public IList<MarketplaceCategory> Categories { get; set; }
        public MarketplacePublisher       Publisher  { get; set; }

        /// <summary>
        /// Collection of offers grouped by marketplace language
        /// </summary>
        public Dictionary<string, List<MarketplaceOffer>> Offers { get; set; }

        public List<string> Marketplaces;

        public MarketplaceApp() {
            Categories   = new List<MarketplaceCategory>();
            Offers       = new Dictionary<string, List<MarketplaceOffer>>();
            Marketplaces = new List<string>();
        }
    }

    public class MarketplaceCategory
    {
        public string Id { get; set; }
        public string IsRoot { get; set; }
        public string Title { get; set; }

        public Dictionary<string, MarketplaceApp> Apps { get; set; }

        public MarketplaceCategory()
        {
            Apps = new Dictionary<string, MarketplaceApp>();
        }
    }

    public class MarketplaceOffer
    {
        public string OfferId { get; set; }
        public string MediaInstanceId { get; set; }
        public decimal Price { get; set; }
        public string PriceCurrencyCode { get; set; }
        public string LicenseRight { get; set; }
        public List<string> PaymentType { get; set; }

        public MarketplaceOffer()
        {
            PaymentType = new List<string>();
        }
    }

    public class MarketplacePublisher
    {
        public string Id { get; set; }
        public string Name { get; set; }

        public Dictionary<string, MarketplaceApp> Apps { get; set; }

        public MarketplacePublisher()
        {
            Apps = new Dictionary<string, MarketplaceApp>();
        }

        public MarketplacePublisher(MarketplacePublisher globalPublisher) : this()
        {
            Id   = globalPublisher.Id;
            Name = globalPublisher.Name;
        }
    }
}
